package cn.pugle.oj.leetcode;

import cn.pugle.oj.catalog.TreeProblem;

/**
 * https://leetcode.com/problems/symmetric-tree/
 * @author tzp
 * @since 2020/10/13
 */
public class LC101 implements TreeProblem {
    public boolean isSymmetric(TreeNode root) {
        if (root == null) return true;
        return isSym(root.left, root.right);
    }

    public boolean isSym(TreeNode left, TreeNode right) {
        if (left == null && right == null) return true;
        if (left != null && right != null)
            return left.val == right.val && isSym(left.left, right.right) && isSym(left.right, right.left);
        return false;
    }

    public static void main(String[] args) {
//        Integer[] a = {1, 2, 4, 3, 5, 7, 10, 6, null, 8, null, 11, 9, 15, null, null, null, 12, null, null, null, 13, null, null, null, null, 14};
        Integer[] a = {1, 2, 2};
        TreeNode treeNode = TreeNode.arrayToTreeNode(a);
        System.out.println(new LC101().isSymmetric(treeNode));
    }
}
